﻿function showDialog(caption, text) {
    $("#dialog").dialog({
        title: caption,
        modal: true,
        position: ["center", "center"],
        buttons: {
            "Закрыть": function () {
                $(this).dialog("close");
            }
        }
    });
    $("#dialog").text('');
    $("#dialog").text(text);
}

function showDialogTake(objname, caption, text) {
    $("#dialog").dialog({
        title: caption,
        modal: true,
        position: ["center", "center"],
        buttons: {
            "Взять": function () {
                ASLEvent("SendTakeResult", caption);
                $("#" + objname).remove();
                $(this).dialog("close");
            },
            "Закрыть": function () {
                $(this).dialog("close");
            }
        }
    });
    $("#dialog").text('');
    $("#dialog").text(text);
}

function showDialogRadio(objname, caption, text, option1, option2, option3, option4, option5) {
    $("#dialog").dialog({
        title: caption,
        modal: true,
        position: ["center", "center"],
        buttons: {
            "Ответить": function () {
                var res = $('input[name=variants]:checked').val();
                if (typeof res != "undefined")
                    ASLEvent("SendDialogResult", res + ";" + objname);
                $(this).dialog("close");
            },
            "Закрыть": function () {
                $(this).dialog("close");
            }
        }
    });
    $("#dialog").text('');
    $('<p>').text(text).appendTo("#dialog");
    $('<input>').attr({ type: 'radio', name: 'variants', value: "1", id: 'rb1' }).appendTo("#dialog");
    $('<label>').attr({ for: 'rb1' }).text(option1).appendTo("#dialog");
    $('</br>').appendTo("#dialog");
    $('<input>').attr({ type: 'radio', name: 'variants', value: "2", id: 'rb2' }).appendTo("#dialog");
    $('<label>').attr({ for: 'rb2' }).text(option2).appendTo("#dialog");
    $('</br>').appendTo("#dialog");
    if (option3.length > 0) 
    {
        $('<input>').attr({ type: 'radio', name: 'variants', value: "3", id: 'rb3' }).appendTo("#dialog");
        $('<label>').attr({ for: 'rb3' }).text(option3).appendTo("#dialog");
        $('</br>').appendTo("#dialog");
        if (option4.length > 0) 
        {
            $('<input>').attr({ type: 'radio', name: 'variants', value: "4", id: 'rb4' }).appendTo("#dialog");
            $('<label>').attr({ for: 'rb4' }).text(option4).appendTo("#dialog");
            $('</br>').appendTo("#dialog");
            if (option5.length > 0) 
            {
                $('<input>').attr({ type: 'radio', name: 'variants', value: "5", id: 'rb5' }).appendTo("#dialog");
                $('<label>').attr({ for: 'rb5' }).text(option5).appendTo("#dialog");
                $('</br>').appendTo("#dialog");
            }
        }
    }
}